package com.chare.Controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.chare.pojo.Employee;
import com.chare.pojo.RespBean;
import com.chare.pojo.RespPageBean;
import com.chare.pojo.Salary;
import com.chare.service.IEmployeeService;
import com.chare.service.ISalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/salary/sobcfg")
public class SalarySobCfgController {
    @Autowired
    private ISalaryService salaryService;
    @Autowired
    private IEmployeeService employeeService;
    @ApiModelProperty(value = "获得所有工资账套")
    @GetMapping("/salaries")
    public List<Salary> getAllSalaries()
    {
        return salaryService.list();
    }
    @ApiModelProperty(value = "获取所有员工账套")
    @GetMapping("/getEmployeeWithSalary")
    public RespPageBean getEmployee(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize)
    {
        return employeeService.getEmloyeeWithSalary(page,pageSize);
    }
    @PutMapping("/")
    @ApiModelProperty("修改所有员工账套")
    public RespBean updateE(Integer empId,Integer salaryId)
    {

      if( employeeService.update(new UpdateWrapper<Employee>().eq("id",empId).set("salaryId",salaryId)))
      {
          return RespBean.success("更新成功");
      }
      return RespBean.error("更新失败");
    }
}
